package com.cee.admin.modules.ca;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cee.admin.common.BaseController;
import com.cee.common.web.result.Result;
import com.cee.domain.modules.ca.query.CaCancelApplicationQuery;
import com.cee.domain.modules.ca.vo.CaCancelApplicationVo;
import com.cee.ds.common.constants.PermissionConstants;
import com.cee.ds.modules.ca.service.ICaCancelApplicationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.io.OutputStream;

/**
 * @author wsz
 * @since 2024/3/11
 */
@RestController
@Tag(name = "项目管理")
@RequestMapping("/api/ca/cancel")
public class CaCancelController extends BaseController {


    @Autowired
    private ICaCancelApplicationService cancelApplicationService;

    @GetMapping("/page")
    @Operation(summary = "碳信用注销台账-分页")
    @RequiresPermissions(PermissionConstants.CA_CANCELLATION_PREFIX + PermissionConstants.READ)
    public Result<IPage<CaCancelApplicationVo>> page(@Valid CaCancelApplicationQuery query) {
        return success(cancelApplicationService.adminPage(query));
    }

    @GetMapping("/report")
    @Operation(summary = "碳信用注销台账-下载报告")
    @RequiresPermissions(PermissionConstants.CA_CANCELLATION_REPORT_PREFIX + PermissionConstants.DOWNLOAD)
    public void applyReport(@RequestParam Long id, OutputStream outputStream) {
        cancelApplicationService.downloadReport(id, outputStream, this::setDownloadResponse);
    }
}